//
//  HZLandscapeIndexView.m
//  Stock_Health
//
//  Created by MayerF on 2017/8/3.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZLandscapeIndexView.h"
#import "MYRadioGroup.h"

@interface HZLandscapeIndexView()
@property (nonatomic, strong)UIScrollView *pScrollView;
@property (nonatomic, strong)UIView *pContentSizeView;
@property (nonatomic, strong)MYRadioGroup *pRadioGroup;
@end

@implementation HZLandscapeIndexView
#pragma mark -
#pragma mark 生命周期
- (instancetype)init{
    self = [super init];
    if (self) {
        [self p_commonInit];
    }
    return self;
}
#pragma mark -
#pragma mark private
- (void)p_commonInit
{
    _pScrollView = [UIScrollView new];
    _pContentSizeView = [UIView new];
    _pRadioGroup = [MYRadioGroup new];

    _pScrollView.showsHorizontalScrollIndicator = NO;
    
    [self addSubview:_pScrollView];
    [_pScrollView addSubview:_pContentSizeView];
    [_pContentSizeView addSubview:_pRadioGroup];
    [self p_initConstraints];
    
    _pRadioGroup.parent = self;
    _pRadioGroup.backgroundColor = [HZCommonTool getThemeColorWithDefaultColor:kMYHexToRGB(0xf5f5f5, 1)];
    NSArray *titleArray = [NSArray arrayWithObjects:
                           @"VOL",
                           @"MACD",
                           @"KDJ",
                           @"RSI",
                           @"BIAS",
                           @"BOLL",
                           @"CCI",
                           @"WR",
                           @"DMA",
                           @"ARBR",
                           @"PSY",nil];
    [_pRadioGroup setRadioGroup:titleArray];
    [_pRadioGroup setHiddenSeparateLine:YES andHiddenUnderline:NO];
    [_pRadioGroup setSelectedButton:0];
    [_pRadioGroup resetAllButtonFont:[UIFont systemFontOfSize:15]];
    
}
- (void)p_initConstraints
{
    [_pScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self);
    }];
    [_pContentSizeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(_pScrollView);
        make.height.mas_equalTo(_pScrollView);
        make.width.mas_equalTo(0);
    }];
    [_pRadioGroup mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(_pContentSizeView);
    }];
    
    [self.superview setNeedsLayout];
    [self.superview layoutIfNeeded];
}
- (void)updateSelectedButton:(NSInteger)tag
{
    [_pRadioGroup setSelectedButton:tag];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    if (CGRectGetWidth(self.frame) < 577) {
        [_pContentSizeView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(577);
        }];
    }else {
        [_pContentSizeView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(CGRectGetWidth(self.frame));
        }];
    }
}
#pragma mark -
- (void)upToParentWithObjc:(id)objc withType:(NSInteger)type withParamter:(id)paramter{
    switch (type) {
        case kHZ_radioGroupClick_Action:
        {
            [self.parent upToParentWithObjc:self withType:KMSClickLandscapeIndexActionType withParamter:paramter];
        }
            break;
            
        default:
            break;
    }
}
- (void)downToChildWithObjc:(id)objc withType:(NSInteger)type withParamter:(id)paramter{
}


@end
